/*

#include "MyOpenCV.h"



#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <cxcore.h>
#include <iostream>
#include <gl\GL.h>
#include <gl\GLU.h> 
#include <Windows.h>
#include <glut.h> 
using namespace std;
using namespace cv ;


IplImage * image;

void MyInit(int ImageWidth,int ImageHeight)
{
	glClearColor(1.0,1.0,1.0,0.0);
	glColor3f(0.0f,0.0f,0.0f);
	glPointSize(1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0,(GLdouble)ImageWidth,0.0,(GLdouble) ImageHeight);

}

void MyDisplay()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_POINTS);
    	for(int i =0; i<image->height;i++)
		{
			uchar * ptr = (uchar *) (image->imageData+i*image->widthStep);
			for(int j=0 ;j<image->width;j++)
			{
				GLdouble Red = (GLdouble)ptr[3*j+2];
				GLdouble Green = (GLdouble)ptr[3*j+1];
				GLdouble Blue = (GLdouble) ptr[3*j];
				glColor3f(Red,Green,Blue);
				glPointSize(1.0);
				glVertex2d(i,j);
			}
		}
	glEnd();


	glFlush();
}



void InitGLWindow(int argc, char** argv,int ImageWidth,int ImageHeight)
{
	 glutInit(&argc,argv);
	 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
	 glutInitWindowSize(ImageWidth,ImageHeight);
	 glutInitWindowPosition(0,0);
	 glutCreateWindow("PictureShower");
	 glutDisplayFunc(MyDisplay);
	 MyInit(ImageWidth,ImageHeight);
	 glutMainLoop();
}

int main(int argc, char** argv) {
     

	CvMat MyMat ; 
	  image  = cvLoadImage(argv[1]);

	FILE * out;
	out = fopen("out.txt","w+");


	int CountWidth ,CountHeight ;
	CountWidth =CountHeight =0 ;

	for(int i =0; i<image->height;i++)
	{
		uchar * ptr = (uchar *) (image->imageData+i*image->widthStep);
		for(int j=0 ;j<image->width;j++)
		{
			fprintf(out,"%d %d %d ", ptr[3*j],ptr[3*j+1],ptr[3*j+2]);
			CountWidth ++;
		}
		fprintf(out,"\n");
		CountHeight++;
	}

	printf("CountWidth = %d ,CountHeight =%d", CountWidth,CountHeight);

	InitGLWindow(argc,argv,image->width,image->height);


	cvNamedWindow("CvShowImage" );
	cvShowImage("CvShowImage",image);

	
	waitKey(0 );
	delete(out);
	cvReleaseImage(&image);
	cvDestroyWindow("CvShowImage");
	return 0;
}
*/
#include <iostream>
using namespace std ;
class HyperKnight
{
public :
	long long countCells(int a, int b, int numRows, int numColumns, int k)
	{
		if(a>b)
			swap(a,b);
		if(numRows>numColumns)
			swap(numRows,numColumns);
		long long c= numColumns;
		long long r =numRows;
		switch(k) 
		{
		case 2:return (long long) 4*a*a ;
		case 3:return (long long )8*a*(b-a) ;
		case 4:return (long long )2*a*(c-2*b+r-2*b) +(long long )4*(b-a)*(b-a)  ;
		case 6:return (long long )2*(b-a)*(c-2*b+r-2*b)  ;
		case 8:return (long long )(c-2*b)*(r-2*b)  ;
		default: return 0;
		}
	}
};
